package com.itheima.controller;

import com.itheima.service.CommentService;
import com.itheima.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;



//圈子互动层
@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentService commentService;

    //分页查询评论列表
    @GetMapping
    public ResponseEntity findComments(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       String movementId) {
        PageResult pr= commentService.findComments(page,pagesize,movementId);
        return ResponseEntity.ok(pr);
    }

    /**
     * 评论喜欢点赞
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String commentsId){
        Integer integer = commentService.commentsLike(commentsId);
        return ResponseEntity.ok(integer);
    }

    /**
     * 评论取消点赞
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String commentsId) {
        Integer likeCount = commentService.commentsLike2(commentsId);
        return ResponseEntity.ok(likeCount);
    }
}
